﻿using System;
using Microsoft.Xna.Framework;

namespace MyCraft.Minecraft_2D.Blocs
{
    class Dirt : Bloc
    {
        #region Attributs
        #endregion

        #region Constructeur
        public Dirt(double timer)
            : base(timer, 10)
        {
            _waitTime = new Random((int)timer).Next(15000, 18000);
            _light = -6;
            _minLight = 0;
            _id = 6;
            _name = "Dirt";
            _percent = 30;
            _color = Color.Sienna;
        }
        #endregion

        #region Proprietes
        #endregion

        #region Methodes
        public override TypeBloc OnNew(Block bloc)
        {
            if (bloc.Bottom == TypeBloc.Grass)
                bloc.Bottom.Type = TypeBloc.Dirt;
            return TypeBloc.Dirt;
        }

        public override Bloc Update(Block block, double timer)
        {
            if (timer > _startTimer + _waitTime)
            {
                if (block.Top != null && block.Top.Type == TypeBloc.Air)
                    foreach (Block b in Map.Circle(block.Position, 1))
                    {
                        if (b != null && b.Type == TypeBloc.Grass && b.Bloc._startTimer + b.Bloc._waitTime <= timer)
                            return BlocSet.GetSingleton()._newBlocs[TypeBloc.Grass].Invoke(new Vector2(0.5f), timer);
                        Refresh(timer, 15000, 18000);
                    }
            }
            return this;
        }
        #endregion
    }
}
